package gui;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * Okno pro zobrazeni jednoduchych informativnich zprav
 * 
 * @author dove
 * 
 */
public class InfoWin extends InternalFrame implements ActionListener {

	private static final long serialVersionUID = 1L;

	private JLabel lText;

	private JButton ok;

	/**
	 * Nastavuje parametry okna
	 * 
	 * @param text
	 *            nazev okna
	 */
	public InfoWin(String text) {

		super(text);
		this.setPosition(200, 200);

		JPanel pan = new JPanel();
		pan.setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();

		c.insets = new Insets(10, 10, 10, 10);
		c.gridx = 0;
		c.gridy = 0;
		lText = new JLabel(text);
		pan.add(lText, c);

		c.gridy = 1;
		ok = new JButton("OK");
		pan.add(ok, c);
		ok.addActionListener(this);

		this.add(pan);
		this.pack();
		this.setMinimumSize(new Dimension(100, 100));
	}

	/**
	 * Nastavuje text ktery ma byt v okne zobrazen
	 * 
	 * @param text
	 *            informacni text
	 */
	public void setText(String text) {
		lText.setText(text);
		this.pack();
		this.updateUI();
	}

	public void actionPerformed(ActionEvent e) {
		this.setVisible(false);
	}
}
